package cn.edu.hust.sse.software7.class3.serviceImpl;

import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

import cn.edu.hust.sse.software7.class3.DAO.EBUserDAO;
import cn.edu.hust.sse.software7.class3.entities.EBUser;
import cn.edu.hust.sse.software7.class3.service.EBUserService;

public class EBUserServiceImpl implements EBUserService {
	private static Logger log;
	EBUserDAO dao = new EBUserDAO();

	public EBUserServiceImpl() {
		if (dao == null) {
			dao = new EBUserDAO();
		}
		log = Logger.getLogger(EBUserServiceImpl.class.getName());
	}

	@Override
	public boolean isExistUser(EBUser user) {
		return dao.isExistUser(user);
	}

	@Override
	public void addUser(EBUser user) {
		boolean checkUser = dao.isExistUser(user);
		if (!checkUser) {
			dao.addUser(user);
		} else {
			log.info("category with the name of " + user.getUserName()
					+ "is already exist.");
		}
	}

	@Override
	public void updateUser(EBUser user) {
		dao.updateUser(user);
	}

	@Override
	public EBUser validateUser(EBUser user) {
		return dao.validateUser(user);
	}

	@Override
	public List<EBUser> getAllUsers() {
		return dao.getAllUsers();
	}
	
	@Override
	public List<EBUser> getAllUsers(Integer rangeValue) {
		return dao.getAllUsers(rangeValue);
	}

	@Override
	public EBUser getUserById(Long userId) {
		return dao.getUserById(userId);
	}

	@Override
	public List<EBUser> getUsersByBirth(Date birth) {
		return dao.getUsersByBirth(birth);
	}

	@Override
	public List<EBUser> getUsersBirthOnToday() {
		return dao.getUsersBirthOnToday();
	}

	@Override
	public List<EBUser> getUsersBirthOnWeek() {
		return dao.getUsersBirthOnWeek();
	}

	@Override
	public List<EBUser> getUsersByEmail(String email) {
		return dao.getUsersByEmail(email);
	}

	@Override
	public void deleteUserById(Long userId) {
		dao.deleteUserById(userId);
	}

	@Override
	public Integer getAllUsersSize() {
		return dao.getAllUsers().size();
	}

}
